﻿namespace YDAT.YdatDB
{
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.Data;
    using System.Collections.Generic;
    using System.Reflection;
    using System.Linq;
    using System.Linq.Expressions;
    using System.ComponentModel;
    using System;

    public partial class Parent
    {
        private bool _primaryFlg = false;

        public bool primaryFlg
        {
            get
            {
                return this._primaryFlg;
            }
            set
            {
                this._primaryFlg = value;
            }
        }
    }


    public partial class Volunteer
    {
        private EntitySet<Parent> _Parents = new EntitySet<Parent>();

        //[Association(Name = "Volunteer_Parent", Storage = "_Parents", OtherKey = "volunteerId")]
        public EntitySet<Parent> Parents
        {
            get
            {
                this._Parents = new EntitySet<Parent>(new Action<Parent>(this.attach_Parents), new Action<Parent>(this.detach_Parents));

                //var parents = from parent in Parent
                //           join volunteerParentXref in VolunteerParentXref
                //                   on parent.parentId equals volunteerParentXref.parentId
                //           where volunteerParentXref.volunteerId == this.volunteerId
                //           select parent;

                //foreach (var parent in parents)
                //    this._Parents.Add(parent);

                foreach (VolunteerParentXref _VolunteerParentXref in VolunteerParentXrefs)
                {
                    _VolunteerParentXref.Parent.primaryFlg = _VolunteerParentXref.primaryFlg;
                    this._Parents.Add(_VolunteerParentXref.Parent);
                }

                return this._Parents;
            }
            set
            {
               
                this.VolunteerParentXrefs.Clear();
                foreach (Parent parent in value)
                {
                    VolunteerParentXref volunteerParentXref = new VolunteerParentXref();
                    volunteerParentXref.volunteerId = this.volunteerId;
                    volunteerParentXref.parentId = parent.parentId;
                    volunteerParentXref.primaryFlg = parent.primaryFlg;
                    volunteerParentXref.Volunteer = this;
                    volunteerParentXref.Parent = parent;
                    this.VolunteerParentXrefs.Add(volunteerParentXref);
                }

                this._Parents.Assign(value);

            }
        }

        //private void attach_Parents(Parent entity)
        //{
        //    this.SendPropertyChanging();
        //    entity.VolunteerParentXrefs. = this;
        //}

        //private void detach_Parents(Parent entity)
        //{
        //    this.SendPropertyChanging();
        //    entity.VolunteerParentXrefs.Volunteer = null;
        //}

    }
}
